﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Drawing;

namespace Model
{
    public enum ShapesType
    {
        FreeStyle,
        Line,
        Rectangle,
        Ellipse
    }

    public static class BuildShape
    {
        public static Shape ShapeBuilder(Point firstPoint,string type)
        {
   
            switch(ShapesTypeConverter(type))
            {
                case ShapesType.FreeStyle:
                    return new FreeStyle(firstPoint);
                case ShapesType.Rectangle:
                    return new Rectangle(firstPoint);
                case ShapesType.Ellipse:
                    return new Ellipse(firstPoint);
                case ShapesType.Line:
                    return new Line(firstPoint);
                default:
                    throw new Exception("This is Impossible");
            }
        }

        private static ShapesType ShapesTypeConverter(string type)
        {
            ShapesType shapeType;
            if (type == null)
                throw new NullReferenceException("String type Cannot be null");
            try
            {
                shapeType = (ShapesType)Enum.Parse(typeof(ShapesType), type, true);
            }
            catch (ArgumentException)
            {
                throw new ArgumentException("type (the string you passed in) is not a ShapeType");
            }
            return shapeType;
        }
    }
}
